package com.example.isoftservice.service.impl;

import com.example.isoftservice.mapper.InstitutionSmallCategoryMapper;
import com.example.isoftservice.pojos.InstitutionSmallCategory;
import com.example.isoftservice.service.InstitutionSmallCategoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class InstitutionSmallCategoryServiceImpl implements InstitutionSmallCategoryService {

    @Resource
    private InstitutionSmallCategoryMapper institutionSmallCategoryMapper;
    @Override
    @Cacheable(cacheNames ="instiutionsmall",key="#pageNo+pageSize")
    public Map<String, Object> searchSmallCategoryList(Integer pageNo, Integer pageSize) {
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(pageNo,pageSize);
        List<Map<String,Object>> resultList = institutionSmallCategoryMapper.selectSmallCategoryList();
        PageInfo<Map<String,Object>> info = new PageInfo(resultList);
        map.put("total",info.getTotal());
        map.put("rows",info.getList());
        return map;
    }

    @Override
    @Cacheable(cacheNames ="instiutionsmall",key="#institutionSmallCategoryId")
    public InstitutionSmallCategory searchSmallCategoryById(Integer institutionSmallCategoryId) {
        return institutionSmallCategoryMapper.selectSmallCategoryById(institutionSmallCategoryId);
    }

    @Override
    @CacheEvict(cacheNames = "instiutionsmall" ,allEntries = true)
    public Boolean addSmallCategory(InstitutionSmallCategory institutionSmallCategory) {
        return institutionSmallCategoryMapper.insertSmallCategory(institutionSmallCategory) == 1 ? true : false;
    }

    @Override
    @CacheEvict(cacheNames = "instiutionsmall" ,allEntries = true)
    public Boolean removeSmallCategoryByIds(Integer[] ids) {
        return institutionSmallCategoryMapper.deleteSmallCategoryByIds(ids) >= 1 ? true : false;
    }

    @Override
    @CacheEvict(cacheNames = "instiutionsmall" ,allEntries = true)
    public Boolean modifySmallCategoryById(InstitutionSmallCategory institutionSmallCategory) {
        return institutionSmallCategoryMapper.updateSmallCategoryById(institutionSmallCategory) == 1 ? true : false;
    }
}
